/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package libase.web.jsf.bean;

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Named;
import libase.entity.Publisher;

/**
 *
 * @author aspr0
 */
@Named
@Stateless
public class PublisherBean extends AbstractBean
{
    private Publisher p = new Publisher();

    public Publisher getP()
    {
        if (fetchId())
        {
            return p = em.find(Publisher.class, id);
        }

        return p;
    }

    public void setP(Publisher p)
    {
        this.p = p;
    }

    public List<Publisher> getPublishers()
    {
        return em.createNamedQuery("Publisher.findAll").getResultList();
    }

    public void create()
    {
        em.persist(p);
        p = new Publisher();//todo use another nice method for clearing persistence
    }

    public void edit()
    {
        em.merge(p);
        p = new Publisher();
    }

    public void remove()
    {
        getP();
        em.remove(p);
        p = new Publisher();
    }
}
